<?php
/**
 * Copyright 2008 francissem (http://www.webmoss.net)(francissem@gmail.com)
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author francissem
 * @copyright 2008 francissem (http://www.webmoss.net)(francissem@gmail.com)
 * @license http://www.apache.org/licenses/LICENSE-2.0
 */


define("__ROOT__",preg_replace("/\\\+/","/",dirname(dirname(__FILE__))));
$setting = parse_ini_file(__ROOT__."/conf.ini",true);

function pathjoin(){
	$args=func_get_args();
	$is_http=ereg("^http://",$args[0]);
	$prehtml="";
	if($is_http)$args[0]=ereg_replace("^http://","/",$args[0]);
	if($is_http) $prehtml="http:/";
	return $prehtml.ereg_replace("(/+)","/",str_replace("\\","/",implode("/",$args)));
}

define("__LIBRARY__",pathjoin(__ROOT__,$setting["structure"]["library_location"]));
define("__DATA__",pathjoin(__ROOT__,$setting["structure"]["data_location"]));
define("__MODULES__",pathjoin(__ROOT__,$setting["structure"]["modules_location"]));
define("__PUBLIC__",pathjoin(__ROOT__,$setting["structure"]["public_location"]));
define("__PUBLIC_URL__",preg_replace("/^".str_replace('/','\/',__ROOT__)."/","",__PUBLIC__));


function _throw_php_error($errno,$errstr,$errfile,$errline,$errcontext){
	throw new System_Exception($errstr,System_Exception::PHP_ERROR,$errfile,$errline);
}

set_include_path(get_include_path().PATH_SEPARATOR.__LIBRARY__);



function __autoload($cls){
	$phpfile = implode("/",explode("_",$cls)).".php";
	if(file_exists(__LIBRARY__."/".$phpfile)){
		require_once($phpfile);
		return;
	}
	require_once($cls.".php");
}

include_once(__LIBRARY__."/global.php");
?>